__author__ = 'shawhen'

from PyQt5.QtCore import *
from PyQt5.QtWidgets import *


class UWidget(QWidget):
    sigAdjustWizardContainerSize = pyqtSignal(int, int, int, int)  # 请调整吾之舞台容器控件的大小

    def __init__(self, parent=None):
        super(UWidget, self).__init__(parent)

    def init(self):
        pass

    def attach_adjust_size_delegate(self, widget):
        """
        为widget附上大小调整的属性，且将其大小调整转发至吾身
        :param widget 这通常（现阶段只能）是一个wizard舞台控件
        """
        widget.adjust_wizard_container_size_delegate = self.adjust_size_delegate

    def adjust_size_delegate(self, width, height, max_width=16777215, max_height=16777215):
        """
        将自个进行大小调整
        """
        self.setFixedSize(16777215, 16777215)  # 解除约束

        if max_width == -1:
            max_width = 16777215
        if max_height == -1:
            max_height = 16777215

        self._resize_animation = QPropertyAnimation(self, "size")
        self._resize_animation.setEasingCurve(QEasingCurve.OutCubic)
        self._resize_animation.setStartValue(QSize(self.width(), self.height()))
        self._resize_animation.setEndValue(QSize(width, height))
        self._resize_animation.setDuration(500)
        self._resize_animation.finished.connect(lambda : self.setMinimumSize(width, height) or self.setMaximumSize(max_width, max_height))
        self._resize_animation.start()